home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_110 / mint / bash110s.zoo / bash-1.10 / builtins / psize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-28  |  1.6 KB  |  74 lines

  1. /* psize.c - Find pipe size. */
  2.  
  3. /* Copyright (C) 1987, 1991 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Bash, the Bourne Again SHell.
  6.  
  7.    Bash is free software; you can redistribute it and/or modify it
  8.    under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 1, or (at your option)
  10.    any later version.
  11.  
  12.    Bash is distributed in the hope that it will be useful, but WITHOUT
  13.    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14.    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  15.    License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with Bash; see the file COPYING.  If not, write to the Free
  19.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21. /*  Write output in 128-byte chunks until we get a sigpipe or write gets an
  22.     EPIPE.  Then report how many bytes we wrote.  We assume that this is the
  23.     pipe size. */
  24.  
  25. #include <stdio.h>
  26. #include <signal.h>
  27. #include <errno.h>
  28.  
  29. #include "../general.h"
  30. extern int errno;
  31.  
  32. int nw;
  33.  
  34. sighandler
  35. sigpipe (sig)
  36.      int sig;
  37. {
  38.   fprintf (stderr, "%d\n", nw);
  39.   exit (0);
  40. }
  41.  
  42. #if !defined (NeXT)
  43. char *
  44. memset (s, c, n)
  45.      register char *s;
  46.      register int c, n;
  47. {
  48.   register char *p = s;
  49.  
  50.   while (--n >= 0)
  51.     *s++ = c;
  52.  
  53.   return (p);
  54. }
  55. #endif /* !NeXT */
  56.  
  57. main (argc, argv)
  58.      int argc;
  59.      char **argv;
  60. {
  61.   char buf[128];
  62.  
  63.   memset (buf, ' ', 128);
  64.   signal (SIGPIPE, sigpipe);
  65.  
  66.   nw = 0;
  67.   for (;;)
  68.     {
  69.       int n;
  70.       n = write (1, buf, 128);
  71.       nw += n;
  72.     }
  73. }
  74.